import { defHttp } from '@/utils/http/axios';

const prefix = 'menu/';
enum Api {
  GetMenuList = '/get-auth-menu',
  List = prefix + '/list',
  Save = prefix + 'save', // 保存 新增/修改
  Details = prefix + 'details', // 保存 新增/修改
  Delete = prefix + 'delete', // 删除
  Import = prefix + 'import', // 导入
  Status = prefix + 'status', // 导入
  SaveHideMenuStatus = prefix + 'save-hide-menu-status', // 导入
  Export = prefix + 'export', // 导出
  Option = prefix + 'option', // 查询下拉框值
  OptionTree = prefix + 'option-tree', // 查询下拉框值
}

/**
 * @description: Get user menu based on id
 */

export const getMenuList = () => {
  return defHttp.get({ url: Api.GetMenuList });
};
/**
 * @description: Get user menu based on id
 */

export const getMenuListTable = (params: {
  illustrate: string | undefined;
  status: string | number | undefined;
}) => {
  return defHttp.get({ url: Api.List, params });
};

/**
 * @description: 获取详情接口
 * @param {{ id: number }} params ID
 */
export function getMenuApi(params: { id: number }) {
  return defHttp.get(
    { url: Api.Details, params },
    {
      errorMessageMode: 'message',
    },
  );
}
/**
 * @description: 修改状态
 * @param {{ id: number }} params ID
 */
export function setMenuStatus(params: { id: number; field: string }) {
  return defHttp.get(
    { url: Api.Status, params },
    {
      errorMessageMode: 'message',
    },
  );
}
/**
 * @description: 修改状态
 * @param {{ id: number }} params ID
 */
export function SaveHideMenuStatus(params: { id: number; field: string }) {
  return defHttp.get(
    { url: Api.Status, params },
    {
      errorMessageMode: 'message',
    },
  );
}

/**
 * @description: 保存接口（新增/修改）
 * @param {any} params 信息
 */
export function saveMenuApi(params: any) {
  return defHttp.post(
    { url: Api.Save, params },
    {
      errorMessageMode: 'message',
    },
  );
}

/**
 * @description: 删除接口
 * @param {{ id: number }} params ID
 */
export function deleteMenuApi(params: { id: number }) {
  return defHttp.get(
    { url: Api.Delete, params },
    {
      errorMessageMode: 'message',
    },
  );
}

/**
 * @description: 导入接口
 * @param {{ id: number }} params ID
 */
export function importMenuApi(params: { id: number }) {
  return defHttp.post(
    { url: Api.Import, params },
    {
      errorMessageMode: 'message',
    },
  );
}

/**
 * @description: 获取下拉框值
 */
export function getMenuOption() {
  return defHttp.get(
    { url: Api.Option },
    {
      errorMessageMode: 'message',
    },
  );
}

/**
 * @description: 获取下拉框值
 */
export function getMenuTreeOption() {
  return defHttp.get(
    { url: Api.OptionTree },
    {
      errorMessageMode: 'message',
    },
  );
}
